home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9771 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.8 KB  |  64 lines

  1. Newsgroups: comp.lang.c++
  2. Path: tank.news.pipex.net!pipex!warwick!bsmail!talisker!nathan
  3. From: nathan@pact.srf.ac.uk (Nathan Sidwell)
  4. Subject: protected access to grandparent class
  5. Message-ID: <Dnqstp.Jo9@uns.bris.ac.uk>
  6. Sender: usenet@uns.bris.ac.uk (Usenet news owner)
  7. Nntp-Posting-Host: talisker.pact.srf.ac.uk
  8. Organization: Inmos
  9. X-Newsreader: TIN [version 1.2 PL2]
  10. Date: Mon, 4 Mar 1996 12:17:49 GMT
  11.  
  12. The following class heirarchy is giving me grief.
  13. -snip
  14. class A {
  15. protected:
  16.   int member;
  17.   void func(A){};
  18. };
  19.  
  20. class B : protected A {
  21. protected:
  22.   void func(B arg) {
  23.     A::func(A(arg));      // ok
  24.   };
  25. };
  26.  
  27. class C : protected B {
  28. protected:
  29.   void func(C arg) {
  30.     A::func(A(arg));      // failed
  31.   };
  32. };
  33. -snip
  34.  
  35. As far as I can determined the line marked 'failed' is class C's equivalent
  36. of the line marked 'ok'. However, g++ 2.7.2 says,
  37.  
  38. foo.cc: In method `void C::func(class C)':
  39. foo.cc:17: fields of `const A' are inaccessible in `C' due to private inheritance
  40. foo.cc:5: in passing argument 1 of `A::A(const A &)'
  41. foo.cc:17: in conversion to type `A'
  42.  
  43. and cfront says,
  44.  
  45. "foo.cc", line 17: error: cast: C* -> base A*; protected base class
  46. "foo.cc", line 17: error:  object or pointer missing for A::func() of type  void A::(A)
  47.  
  48. however, SGI CC accepts the code.
  49.  
  50. I can't see anything in 11.2 of the draft standard which indicates that the rule
  51. it describes cannot be applied recursively -- it doesn't describe any other
  52. method for determining the access to grandparent members.
  53.  
  54. Is my understanding incomplete or are g++ and cfront confused?
  55.  
  56. nathan
  57.  
  58.  
  59. --
  60. Nathan Sidwell                         Holder of the Xmris home page
  61. Chameleon Architecture Group at SGS-Thomson, formerly Inmos
  62. http://www.pact.srf.ac.uk/~nathan/                  Tel 0117 9707182
  63. nathan@inmos.co.uk or nathan@bristol.st.com or nathan@pact.srf.ac.uk
  64.